﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.IE;
using System.Collections.ObjectModel;
using Selenium;

namespace AutomationTestCases
{
    public class AutomationTestBase
    {
        protected IWebDriver browser;

        public AutomationTestBase()
        {
            if (browser == null)
                browser = new InternetExplorerDriver();
            //browser = new ChromeDriver();
            //DefaultSelenium sele = new DefaultSelenium();
        }

        #region Help methods

        public void GoToUrl(string url)
        {
            browser.Navigate().GoToUrl(url);
        }


        public ReadOnlyCollection<IWebElement> FindElementsById(string id)
        {
            return browser.FindElements(By.Id(id));
        }

        public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
        {
            return browser.FindElements(By.ClassName(className));
        }

        public ReadOnlyCollection<IWebElement> FindElementsByName(string name)
        {
            return browser.FindElements(By.Name(name));
        }

        public IWebElement FindElementByName(string name)
        {
            return browser.FindElement(By.Name(name));
        }

        public IWebElement FindElementById(string id)
        {
            return browser.FindElement(By.Id(id));
        }

        public IWebElement FindElementBySelector(string cssSelector)
        {
            return browser.FindElement(By.CssSelector(cssSelector));
        }

        public IWebElement FindElementByXPath(string xpath)
        {
            return browser.FindElement(By.XPath(xpath));
        }

        public IWebElement FindElementByClass(string className)
        {
            return browser.FindElement(By.ClassName(className));
        }

        public string GetPageTitle()
        {
            return browser.Title;
        }

        #endregion

        public void TearDown()
        {
            browser.Quit();
        }
    }
}
